<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // // ES5继承
        // function Person(name){
        //     this.name = name;
        // }
        // Person.prototype.fn = function(){
        //     console.log('fn');
        // }
        // function Student (name){
        //     Person.call(this,name)
        // }
        //         // 可能会造成引用问题
        // Student.prototype = Person.prototype
        // Student.prototype.constructor = Student

        // // 解决引用问题
        // function Link(){};
        // Link.prototype = Person.prototype()
        // Student.prototype = new Link()
        // Student.prototype.constructor = Student

        // ES6继承
        class Person{
            constructor(name){
                this.name = name;
            }
            fn(){
                console.log('fn');
            }
        }

        //子类没有constructor
        // class Student extends Person{}
        // 子类有constructor,要调用一下super()
        class Student extends Person{
            constructor(name){
                super(name);
            }
        }
        let s = new Student('张三')
        console.log(s);
        s.fn()
    </script>
</body>
</html>